﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<BugzX.Models.ViewBugViewData>" %>

<b id="bugComponent"></b>

<p><b>Number:&nbsp;</b><span id="spanNumber"></span></p>

<p id="bugDescription"></p>

<p><b>Owner:&nbsp;</b><span id="bugOwner"></span></p>
<p><b>Stamp:&nbsp;</b><span id="bugStamp"></span></p>
<p><b>Type:&nbsp;</b><span id="bugType"></span></p>
<p><b>Status:&nbsp;</b><span id="bugStatus"></span></p>

<script type="text/javascript">

    function setupViewBugLoggedOut() {

        var bugId = $("#formViewBug").data("bugid");

        $.getJSON("/services/Bugs.ashx",
            {
                action: "getbug",
                bugId: bugId
            },
            function (data) {

                var d = data[0];

                $("#spanNumber").html(d.bugId);
                $("#bugComponent").html(d.component);
                $("#bugDescription").html(d.description);
                $("#bugOwner").html(d.ownerName);
                $("#bugStamp").html(d.stamp);

                setType(d);
                setStatus(d);
            }
        );
    }

    function setType(bug) {

        var typeUrl = "/Content/images/";
        var typeName = "";

        if (bug.type == 0) {

            typeUrl += "list-bug.png";
            typeName = "bug";
        } else {

            typeUrl += "list-todo.png";
            typeName = "todo";
        }

        $("#bugType").html("<img src=\"" + typeUrl + "\" alt=\"" + typeName + "\" />");
    }

    function setStatus(bug) {

        var status = "";

        if (bug.status == 0) {

            status = "Open";
        }
        else if (bug.status == 1) {

            status = "Fixed";
        }
        else if (bug.status == 2) {

            status = "Closed";
        }
        else if (bug.status == 3) {

            status = "Won't Fix";
        }

        $("#bugStatus").html(status);
    }

</script>